<?php

class Quad_Controller extends Quad_Observable implements Quad_Controller_Interface, Quad_Mvc_Interface {
	
	protected $_view;
	
	protected $_frontController;
	
	public function __construct(Quad_FrontController_Interface $frontController) {
		$this->_frontController = $frontController;
	}
	
	public function &__get($prop) {
		// if not declared, 
		switch ($prop) {
			case 'view':
				return $this->getView();
			
		  case 'session':
			  return $_SESSION;
  	}
	}
  
  public function preDispatch() {}
  
  public function postDispatch() {}
		
	public function redirect($url, $getParams = array()) {
		return $this->getRouter()->redirect($url, $getParams);
	}
	
	public function forward($controller = 'index', $action = 'index', $moreParams = array()) {
		return $this->getRouter()->forward($controller, $action, $moreParams);
	}
	
	public function getView() {
		if (!$this->_view) {
      $viewClass = $this->getBootstrap()->viewClass;
			$this->_view = new $viewClass($this);			
	  }
		return $this->_view;
	}
	
	public function getFrontController() {
		return $this->_frontController;
	}
	
	public function getController() {
		return $this;
	}
	
	public function getBootstrap() {
		return $this->getFrontController()->getBootstrap();
	}
	
	public function getRouter() {
		return $this->getFrontController()->getRouter();
	}

	public function getUrl() {
		return $this->getBootstrap()->getUrl();
	}

}